package com.cs.framework.web.context;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cs.framework.core.context.Context;
import com.cs.framework.web.view.ViewInfo;

/**
 * Action上下文
 * 
 * @author hedongzhou
 * 
 */
public class ActionContext implements Context {

	/**
	 * 上下文
	 */
	private Context context;

	/**
	 * 请求
	 */
	private HttpServletRequest request;

	/**
	 * 响应
	 */
	private HttpServletResponse response;

	/**
	 * 视图信息
	 */
	private ViewInfo viewInfo = new ViewInfo();

	public ActionContext(Context context, HttpServletRequest request, HttpServletResponse response) {
		this.context = context;
		this.request = request;
		this.response = response;
	}

	/**
	 * 初始化
	 */
	public void init() {
	}

	/**
	 * 获取属性配置信息
	 */
	public Map<String, Object> getPropertyMap() {
		return context.getPropertyMap();
	}

	/**
	 * 获取属性配置信息
	 * 
	 * @param key
	 *            键值
	 * @return
	 */
	public Object getProperty(String key) {
		return context.getProperty(key);
	}

	/**
	 * 获取bean
	 * 
	 * @param name
	 *            bean名称
	 * @return
	 */
	public Object getBean(String name) {
		return context.getBean(name);
	}

	/**
	 * 获取bean
	 * 
	 * @param <T>
	 * @param name
	 *            bean名称
	 * @param requiredType
	 *            bean类型
	 * @return
	 */
	public <T> T getBean(String name, Class<T> requiredType) {
		return context.getBean(name, requiredType);
	}

	/**
	 * 获取bean
	 * 
	 * @param <T>
	 * @param requiredType
	 *            bean类型
	 * @return
	 */
	public <T> T getBean(Class<T> requiredType) {
		return context.getBean(requiredType);
	}

	/**
	 * 获取请求
	 * 
	 * @return
	 */
	public HttpServletRequest getRequest() {
		return request;
	}

	/**
	 * 获取响应
	 * 
	 * @return
	 */
	public HttpServletResponse getResponse() {
		return response;
	}

	/**
	 * 获取视图信息
	 * 
	 * @return
	 */
	public ViewInfo getViewInfo() {
		return viewInfo;
	}

}
